from rbt.ic import IndexCalculator


class BnMosRecoverIC(IndexCalculator):
    def __init__(self):
        super().__init__(1)

    def calculate(self, new_data):
        self.result = []
        buy_volume = new_data["taker_buy_base_asset_volume"]
        buy_amount = new_data["taker_buy_quote_asset_volume"]
        if buy_volume > 0:
            buy_price = buy_amount / buy_volume
            self.result.append(
                {"side": "buy", "price": buy_price, "volume": buy_volume}
            )
        sell_volume = new_data["volume"] - buy_volume
        sell_amount = new_data["quote_asset_volume"] - buy_amount
        if sell_volume > 0:
            sell_price = sell_amount / sell_volume
            self.result.append(
                {"side": "sell", "price": sell_price, "volume": sell_volume}
            )
